#ifndef __TOYM__NET__EVENT_LOOP_THREAD_H__
#define __TOYM__NET__EVENT_LOOP_THREAD_H__

#include <thread>
#include <memory>
#include <mutex>
#include <condition_variable>
#include "net/Callables.h"

namespace toym
{
namespace net
{

class EventLoop;

class EventLoopThread {
public:
    EventLoopThread(ThreadInitCallback_t cb = ThreadInitCallback_t(), 
                    const std::string& threadName = std::string());
    
    ~EventLoopThread();
    EventLoop* startLoop();
private:

    void threadFunc();

    EventLoop* m_loop;
    std::unique_ptr<std::thread> m_thread;
    std::mutex m_mutex;
    std::condition_variable m_cond;
    bool m_exiting;
    ThreadInitCallback_t m_threadInitCb;
};

} // namespace net

} // namespace toym


#endif